package com.beg.cant.controller;

import com.beg.cant.comment.result.Result;
import com.beg.cant.entity.Gift;
import com.beg.cant.service.GiftService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/gifts")
@Tag(name = "礼物管理", description = "礼物的增删改查接口")
public class GiftController {
    @Autowired
    private GiftService giftService;

    @PostMapping
    @Operation(summary = "创建礼物", description = "添加一个新的礼物")
    public Result<String> createGift(@RequestBody Gift gift) {
        giftService.save(gift);
        return Result.success("礼物添加成功");
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除礼物", description = "根据ID删除礼物")
    public Result<String> deleteGift(@PathVariable Integer id) {
        giftService.removeById(id);
        return Result.success("礼物删除成功");
    }

    @PutMapping
    @Operation(summary = "更新礼物", description = "修改礼物信息")
    public Result<String> updateGift(@RequestBody Gift gift) {
        giftService.updateById(gift);
        return Result.success("礼物更新成功");
    }
    
    @GetMapping("/list")
    @Operation(summary = "查询所有礼物", description = "获取全部礼物列表")
    public Result<List<Gift>> getAllGifts() {
        List<Gift> giftList = giftService.list();
        return Result.success(giftList);
    }
}